$(() => {
    $(".editMember").click(function () {
        $('#personalInfoModal').modal('show');
    });


        $("#saveButton").click(function () {
            let id = $("#userId").val();
            let address = $("#address").val();
            $.ajax({
                url: ctx + "settle/update",
                method: "POST",
                data: {
                    id: id,
                    address: address
                },
                success: function (resp) {
                    console.log(resp);
                    if (resp.code == 200) {
                        $('#personalInfoModal').modal('hide');
                         window.location.reload();
                    } else {
                        $('#personalInfoModal').modal('hide');
                        alert(resp.msg);
                    }
                },
                error: function () {
                    Swal.fire({
                        text: '操作失败',
                        icon: "error",
                        iconColor: "#f05b72"
                    });
                }
            });
        });

    $('#saveOrder').click(function () {
        // 从页面上显示地址的元素中获取地址信息，而不是从模态框的输入框中获取
        let address = $(".user_address_label").text();
        console.log(address);
        if (address ==='' || address === '无') {
            Swal.fire({
                text: "请填写收货信息",
                icon: "error",iconColor:"#f05b72",
            });
            return;
        }
        
        // 获取memberId
        let memberId = $("#memberId").val();
        
        Swal.fire({
            title: "确认框",
            text: "是否提交订单",
            icon: "success",iconColor:"#1d953f",
            showCancelButton: true,
            confirmButtonText: '确认',
            cancelButtonText: '取消'
        }).then((flag) => {
                if (flag.value) {

                    window.location.reload();
                    window.location.href = '/shopping/orders/save?memberId=' + memberId;
                }
            }
        );
    });

});